home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3.iso / chapte19 / timefmt2.c < prev    next >
C/C++ Source or Header  |  1996-04-29  |  6KB  |  216 lines

  1.  
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include "TimeFmt2.h"
  5. #include <vfw.h>
  6.  
  7.  
  8. #if defined (WIN32)
  9.     #define IS_WIN32 TRUE
  10. #else
  11.     #define IS_WIN32 FALSE
  12. #endif
  13.  
  14. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  15. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  16. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  17.  
  18.  
  19. HINSTANCE hInst;   // current instance
  20.  
  21. LPCTSTR lpszAppName = "MyApp";
  22. LPCTSTR lpszTitle   = "My Application"; 
  23.  
  24. // the rest of the stuff
  25. //......................
  26.  
  27. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  28.  
  29.  
  30. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  31.                       LPTSTR lpCmdLine, int nCmdShow)
  32. {
  33.    MSG      msg;
  34.    HWND     hWnd; 
  35.    WNDCLASS wc;
  36.  
  37.    wc.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  38.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  39.    wc.cbClsExtra    = 0;                      
  40.    wc.cbWndExtra    = 0;                      
  41.    wc.hInstance     = hInstance;              
  42.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  43.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  44.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  45.    wc.lpszMenuName  = lpszAppName;              
  46.    wc.lpszClassName = lpszAppName;              
  47.  
  48.    if ( IS_WIN95 )
  49.    {
  50.       if ( !RegisterWin95( &wc ) )
  51.          return( FALSE );
  52.    }
  53.    else if ( !RegisterClass( &wc ) )
  54.       return( FALSE );
  55.  
  56.    hInst = hInstance; 
  57.  
  58.    hWnd = CreateWindow( lpszAppName, 
  59.                         lpszTitle,    
  60.                         WS_OVERLAPPEDWINDOW, 
  61.                         CW_USEDEFAULT, 0, 
  62.                         CW_USEDEFAULT, 0,  
  63.                         NULL,              
  64.                         NULL,              
  65.                         hInstance,         
  66.                         NULL               
  67.                       );
  68.  
  69.    if ( !hWnd ) 
  70.       return( FALSE );
  71.  
  72.    ShowWindow( hWnd, nCmdShow ); 
  73.    UpdateWindow( hWnd );         
  74.  
  75.    while( GetMessage( &msg, NULL, 0, 0) )   
  76.    {
  77.       TranslateMessage( &msg ); 
  78.       DispatchMessage( &msg );  
  79.    }
  80.  
  81.    return( msg.wParam ); 
  82. }
  83.  
  84.  
  85. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  86. {
  87.     WNDCLASSEX wcex;
  88.  
  89.    wcex.style         = lpwc->style;
  90.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  91.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  92.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  93.    wcex.hInstance     = lpwc->hInstance;
  94.    wcex.hIcon         = lpwc->hIcon;
  95.    wcex.hCursor       = lpwc->hCursor;
  96.    wcex.hbrBackground = lpwc->hbrBackground;
  97.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  98.    wcex.lpszClassName = lpwc->lpszClassName;
  99.  
  100.    // Added elements for Windows 95.
  101.    //...............................
  102.    wcex.cbSize = sizeof(WNDCLASSEX);
  103.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  104.                             IMAGE_ICON, 16, 16,
  105.                             LR_DEFAULTCOLOR );
  106.             
  107.    return RegisterClassEx( &wcex );
  108. }
  109.  
  110.  
  111. HWND hMCIWnd = NULL;   // MCIWnd window handle
  112.  
  113. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  114. {
  115.    switch( uMsg )
  116.    {
  117.       case WM_CREATE :
  118.               // create MCIWnd window
  119.               //.....................
  120.               
  121.               hMCIWnd = MCIWndCreate(hWnd, hInst, 
  122.                                      WS_VISIBLE | 
  123.                                      WS_CHILD | 
  124.                                      WS_OVERLAPPED |
  125.                                      WS_CAPTION |
  126.                                      WS_BORDER |
  127.                                      MCIWNDF_NOTIFYMODE |
  128.                                      MCIWNDF_SHOWALL, 
  129.                                      "Sample.avi"
  130.                                     );
  131.                           
  132.               if (hMCIWnd)
  133.                   MCIWndPlay(hMCIWnd);
  134.               else
  135.               {
  136.                   MessageBox(hWnd, "Error creating MCIWnd window...", 
  137.                              NULL, MB_OK);
  138.                   DestroyWindow( hWnd );
  139.               }
  140.               break;
  141.  
  142.       case WM_COMMAND :
  143.               switch( LOWORD( wParam ) )
  144.               {
  145.                  case IDM_TIME_MS :
  146.                          if (MCIWndGetTimeFormat(hMCIWnd, NULL, 0) 
  147.                              != MCI_FORMAT_MILLISECONDS)
  148.                          {
  149.                              MCIWndSetTimeFormat(hMCIWnd, "ms");
  150.                          }
  151.                          break;
  152.                          
  153.                  case IDM_TIME_FRAMES :
  154.                          if (MCIWndGetTimeFormat(hMCIWnd, NULL, 0) 
  155.                              != MCI_FORMAT_FRAMES)
  156.                          {
  157.                              MCIWndSetTimeFormat(hMCIWnd, "frames");
  158.                          }
  159.                          break;
  160.  
  161.                  case IDM_EXIT :
  162.                         DestroyWindow(hWnd);
  163.                         break;
  164.               }
  165.               break;
  166.  
  167.       case WM_DESTROY :
  168.               // destroy MCIWnd, if one exists
  169.               //..............................
  170.  
  171.               if (hMCIWnd)
  172.                   MCIWndDestroy(hMCIWnd);
  173.  
  174.               PostQuitMessage(0);
  175.               break;
  176.  
  177.       default :
  178.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  179.    }
  180.  
  181.    return( 0L );               
  182. }
  183.  
  184.  
  185. LRESULT CALLBACK About( HWND hDlg,           
  186.                         UINT message,        
  187.                         WPARAM wParam,       
  188.                         LPARAM lParam)
  189. {
  190.    switch (message) 
  191.    {
  192.        case WM_INITDIALOG: 
  193.                return (TRUE);
  194.  
  195.        case WM_COMMAND:                              
  196.                if (   LOWORD(wParam) == IDOK         
  197.                    || LOWORD(wParam) == IDCANCEL)    
  198.                {
  199.                        EndDialog(hDlg, TRUE);        
  200.                        return (TRUE);
  201.                }
  202.                break;
  203.    }
  204.  
  205.    return (FALSE); 
  206. }
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.